﻿Public Class Overtime
    Dim i As Int16 = 1
    Private Sub OverTime_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        UI.FormatDataGrid(DataGridView1)
        loademp()
        Button4.Visible = False
    End Sub
    Private Sub loadsex()

    End Sub
    Private Sub loademp()
        cboemp.DisplayMember = "emp_name"
        cboemp.ValueMember = "emp_id"
        cboemp.DataSource = cmd.ExecuteDataTable("SELECT emp_id,emp_name FROM employee_tbl WHERE active=1")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DataGridView1.Rows.Add(New String() {i, cboemp.SelectedValue, cboemp.Text, dtpo.Value, txtany.Text})
        i += 1
    End Sub

    Private Sub btndel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndel.Click
        Dim row = Me.DataGridView1.SelectedRows(0)

        If Not MessageBox.Show("តើអ្នកពិតជាចង់លុបមែនទេ?") = Windows.Forms.DialogResult.OK Then
            Exit Sub
        End If
        DataGridView1.Rows.Remove(row)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim row = Me.DataGridView1.SelectedRows(0)
        MessageBox.Show(row.Cells(1).Value)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim id As Integer
        Dim da As String
        Dim de As String

        For j = 0 To DataGridView1.Rows.Count - 1
            id = DataGridView1.Rows(j).Cells("empid").Value
            da = DataGridView1.Rows(j).Cells("odate").Value
            de = DataGridView1.Rows(j).Cells("anny").Value.ToString
            'MessageBox.Show(id)
            action.ExecuteNonquery("INSERT INTO overtime_tbl values('" & id & "','" & da & "',null,null,N'" & de & "',1)")
        Next
        MessageBox.Show("Add Sucess")
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Close()
    End Sub
End Class